//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.finance;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.DicTranCodeDao;
import com.aidong.model.wills.DicTranCode;
import com.aidong.web.controller.BaseController;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"dicTranCode"})
public class DicTranCodeController extends BaseController {
    @Resource
    DicTranCodeDao dicTranCodeDao;

    public DicTranCodeController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return new ModelAndView("finance/trancode/list");
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "tranCode",required = false) String tranCode, @RequestParam(value = "codeName",required = false) String codeName, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        cd.eq("TranCode", tranCode);
        cd.like("CodeName", "%" + codeName + "%");
        this.dicTranCodeDao.queryPageList(pg, cd, (new OrderSet()).asc("TranCode"));
        ModelAndView mv = new ModelAndView("finance/trancode/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        DicTranCode dicTrancode = new DicTranCode();
        ModelAndView mv = new ModelAndView("finance/trancode/edit");
        mv.addObject("dicTranCode", dicTrancode);
        mv.addObject("tranCodeType", this.getTypeList("tranCodeType"));
        mv.addObject("tranCodeCategory", this.getTypeList("tranCodeCategory"));
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("dicTranCode") DicTranCode dicTrancode) {
        if(this.chkNull(dicTrancode.getTranCode())) {
            return this.getResult(false, "请输入科目代码");
        } else if(this.chkNull(dicTrancode.getCodeName())) {
            return this.getResult(false, "请输入科目名称");
        } else if(this.chkNull(dicTrancode.getType())) {
            return this.getResult(false, "请输入科目类型");
        } else {
            dicTrancode.setCreateUser(this.getLoginUserCode());
            dicTrancode.setCreateTime(new Date());
            dicTrancode.setUpdateTime(new Date());

            try {
                this.dicTranCodeDao.add(dicTrancode);
                this.reloadTypeList("tranCode");
                this.addUserLog("科目代码设置", "编号:" + dicTrancode.getTranCode() + ",名称:" + dicTrancode.getCodeName());
            } catch (Exception var3) {
                this.log.error("add dicTrancode", var3);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "保存完成");
        }
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@RequestParam("tranCode") String tranCode) {
        DicTranCode dicTrancode = (DicTranCode)this.dicTranCodeDao.getById(tranCode);
        if(dicTrancode == null) {
            return this.showAlert("没有这个记录");
        } else {
            ModelAndView mv = new ModelAndView("finance/trancode/edit");
            mv.addObject("dicTranCode", dicTrancode);
            mv.addObject("tranCodeType", this.getTypeList("tranCodeType"));
            mv.addObject("tranCodeCategory", this.getTypeList("tranCodeCategory"));
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("dicTrancode") DicTranCode dicTrancode) {
        if(this.chkNull(dicTrancode.getTranCode())) {
            return this.getResult(false, "请输入科目代码");
        } else if(this.chkNull(dicTrancode.getCodeName())) {
            return this.getResult(false, "请输入科目名称");
        } else {
            DicTranCode dicTrancode1 = (DicTranCode)this.dicTranCodeDao.getById(dicTrancode.getTranCode());
            if(dicTrancode1 == null) {
                return this.getResult(false, "没有这个记录");
            } else {
                dicTrancode1.setCodeName(dicTrancode.getCodeName());
                dicTrancode1.setType(dicTrancode.getType());
                dicTrancode1.setAdjCode(dicTrancode.getAdjCode());
                dicTrancode1.setAllowCode(dicTrancode.getAllowCode());
                dicTrancode1.setCategory(dicTrancode.getCategory());
                dicTrancode1.setUpdateTime(new Date());

                try {
                    this.dicTranCodeDao.update(dicTrancode1);
                    this.reloadTypeList("tranCode");
                    this.addUserLog("修改科目代码设置", "编号:" + dicTrancode1.getTranCode() + ",名称:" + dicTrancode1.getCodeName());
                } catch (Exception var4) {
                    this.log.error("edit dicTrancode", var4);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("tranCode") String typeCode) {
        DicTranCode dicTrancode = (DicTranCode)this.dicTranCodeDao.getById(typeCode);
        if(dicTrancode == null) {
            return this.getResult(false, "没有这个记录");
        } else {
            try {
                this.dicTranCodeDao.delete(dicTrancode);
                this.reloadTypeList("tranCode");
                this.addUserLog("删除科目代码设置", "编号:" + dicTrancode.getTranCode() + ",名称:" + dicTrancode.getCodeName());
            } catch (Exception var4) {
                this.log.error("del dicTrancode", var4);
                return this.getResult(false, "删除发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }
}
